package com.magina.antiPro.controller;

import com.magina.antiPro.webSocket.WebSocketServer;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.websocket.server.PathParam;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Api(value = "/webSocket", description = "测试webSocket接口")
@RestController
@RequestMapping("/webSocket")
public class WebSocketController {

    //页面请求
    @GetMapping("/socket/{cid}")
    public Boolean socket(@PathParam(value = "cid") String cid, HttpServletRequest request) {
        request.getSession().setAttribute("ssid",cid);
        return true;
    }

    @GetMapping(value="/socket/push/{cid}")
    public @ResponseBody Map<String,Object> pushVideoListToWeb(@PathVariable(value = "cid")  String cid) {
        Map<String,Object> result =new HashMap<String,Object>();

        try {
            WebSocketServer.sendInfo("有新客户呼入,sltAccountId:"+UUID.randomUUID(),cid);
            result.put("operationResult", true);
        }catch (IOException e) {
            result.put("operationResult", true);
        }
        return result;
    }

}
